/*
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.nanhill.commons.id.uuid;

/**
 * <p>
 * Constant values commonly needed in the uuid classes.
 * </p>
 * 
 * @author Commons-Id Team
 * @version $Revision: 1.1 $ $Date: 2006/09/20 06:55:58 $
 * 
 */
public final class Constants {

	// ** Magic number constants
	/** Bits in a UUID. */
	public static final int UUID_BIT_LENGTH = 128;

	/** Number of bytes in a UUID. */
	public static final int UUID_BYTE_LENGTH = 16;

	// ** Formatting and validation constants
	/** Chars in a UUID String. */
	public static final int UUID_UNFORMATTED_LENGTH = 32;

	/** Chars in a UUID String. */
	public static final int UUID_FORMATTED_LENGTH = 36;

	/** Token length of '-' separated tokens. */
	public static final int TOKENS_IN_UUID = 5;

	/** Array to check tokenized UUID's segment lengths */
	public static final int[] TOKEN_LENGTHS = { 8, 4, 4, 4, 12 };

	/** Insertion point 1 for dashes in the string format */
	public static final int FORMAT_POSITION1 = 8;

	/** Insertion point 2 for dashes in the string format */
	public static final int FORMAT_POSITION2 = 13;

	/** Insertion point 3 for dashes in the string format */
	public static final int FORMAT_POSITION3 = 18;

	/** Insertion point 4 for dashes in the string format */
	public static final int FORMAT_POSITION4 = 23;

	/** The string prefix for a urn UUID identifier. */
	public static final String URN_PREFIX = "urn:uuid:";

	// ** UUID Variant Constants
	/**
	 * UUID variant bits described in the IETF Draft MSB order, this is the
	 * "Reserved, NCS backward compatibility field" 0 x x with unknown bits as 0
	 */
	public static final int VARIANT_NCS_COMPAT = 0;

	/**
	 * UUID variant bits described in the IETF Draft MSB order, this is the IETF
	 * Draft memo variant field 1 0 x with unknown bits as 0
	 */
	public static final int VARIANT_IETF_DRAFT = 2;

	/**
	 * UUID variant bits described in the IETF Draft MSB order, this is the IETF
	 * Draft "Microsoft Corporation" field variant 1 1 0 x with unknown bits as
	 * 0
	 */
	public static final int VARIANT_MS = (byte) 6;

	/**
	 * UUID variant bits described in the IETF Draft MSB order, this is the
	 * "Future Reserved variant 1 1 1 x with unknown bits as 0
	 */
	public static final int VARIANT_FUTURE = 7;

	// ** UUID Version Constants
	/** Version one constant for UUID version one of four */
	public static final int VERSION_ONE = 1;

	/** Version two constant for UUID version two of four */
	public static final int VERSION_TWO = 2;

	/** Version three constant for UUID version three of four */
	public static final int VERSION_THREE = 3;

	/** Version four constant for UUID version four of four */
	public static final int VERSION_FOUR = 4;

	/** Version five constant for UUID version five - identical to version 3 */
	public static final int VERSION_FIVE = 3;

	/**
	 * Constants that correspond to the encoding being used, a la
	 * http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-04.txt.
	 * Current legal values are "MD5" and "SHA1"
	 */
	public static final String MD5_ENCODING = "MD5";

	public static final String SHA1_ENCODING = "SHA1";

	// ** Exception message constants
	/** Message indicating this is not a version one UUID */
	public static final String WRONG_VAR_VER_MSG = "Not a ietf variant 2 or version 1 (time-based UUID)";

	// ** Array positions and lengths of UUID fields ** //
	/** Byte length of time low field */
	public static final int TIME_LOW_BYTE_LEN = 4;

	/** Byte length of time low field */
	public static final int TIME_MID_BYTE_LEN = 2;

	/** Byte length of time low field */
	public static final int TIME_HI_BYTE_LEN = 2;

	/** Timestamp byte[] position of time low field */
	public static final int TIME_LOW_TS_POS = 4;

	/** Timestamp byte[] position mid field */
	public static final int TIME_MID_TS_POS = 2;

	/** Timestamp byte[] position hi field */
	public static final int TIME_HI_TS_POS = 0;

	/** uuid array position start of time low field */
	public static final int TIME_LOW_START_POS = 0;

	/** uuid array position start of mid field */
	public static final int TIME_MID_START_POS = 4;

	/** uuid array position start of hi field */
	public static final int TIME_HI_START_POS = 6;

	/** Byte position of the clock sequence and reserved field */
	public static final short TIME_HI_AND_VERSION_BYTE_6 = 6;

	/** Byte position of the clock sequence and reserved field */
	public static final short CLOCK_SEQ_HI_AND_RESERVED_BYTE_8 = 8;
}
